1 /*
2  * This file is part of gtkD.
3  *
4  * gtkD is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU Lesser General Public License
6  * as published by the Free Software Foundation; either version 3
7  * of the License, or (at your option) any later version, with
8  * some exceptions, please read the COPYING file.
9  *
10  * gtkD is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public License
16  * along with gtkD; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA
18  */
19 
20 // generated automatically - do not change
21 // find conversion definition on APILookup.txt
22 // implement new conversion functionalities on the wrap.utils pakage
23 
24 
25 module gtk.SortListModel;
26 
27 private import gio.ListModelIF;
28 private import gio.ListModelT;
29 private import glib.ConstructionException;
30 private import gobject.ObjectG;
31 private import gtk.Sorter;
32 private import gtk.c.functions;
33 public  import gtk.c.types;
34 
35 
36 /**
37  * A `GListModel` that sorts the elements of an underlying model
38  * according to a `GtkSorter`.
39  * 
40  * The model is a stable sort. If two items compare equal according
41  * to the sorter, the one that appears first in the original model will
42  * also appear first after sorting.
43  * Note that if you change the sorter, the previous order will have no
44  * influence on the new order. If you want that, consider using a
45  * `GtkMultiSorter` and appending the previous sorter to it.
46  * 
47  * The model can be set up to do incremental sorting, so that
48  * sorting long lists doesn't block the UI. See
49  * [method@Gtk.SortListModel.set_incremental] for details.
50  * 
51  * `GtkSortListModel` is a generic model and because of that it
52  * cannot take advantage of any external knowledge when sorting.
53  * If you run into performance issues with `GtkSortListModel`,
54  * it is strongly recommended that you write your own sorting list
55  * model.
56  */
57 public class SortListModel : ObjectG, ListModelIF
58 {
59 	/** the main Gtk struct */
60 	protected GtkSortListModel* gtkSortListModel;
61 
62 	/** Get the main Gtk struct */
63 	public GtkSortListModel* getSortListModelStruct(bool transferOwnership = false)
64 	{
65 		if (transferOwnership)
66 			ownedRef = false;
67 		return gtkSortListModel;
68 	}
69 
70 	/** the main Gtk struct as a void* */
71 	protected override void* getStruct()
72 	{
73 		return cast(void*)gtkSortListModel;
74 	}
75 
76 	/**
77 	 * Sets our main struct and passes it to the parent class.
78 	 */
79 	public this (GtkSortListModel* gtkSortListModel, bool ownedRef = false)
80 	{
81 		this.gtkSortListModel = gtkSortListModel;
82 		super(cast(GObject*)gtkSortListModel, ownedRef);
83 	}
84 
85 	// add the ListModel capabilities
86 	mixin ListModelT!(GtkSortListModel);
87 
88 
89 	/** */
90 	public static GType getType()
91 	{
92 		return gtk_sort_list_model_get_type();
93 	}
94 
95 	/**
96 	 * Creates a new sort list model that uses the @sorter to sort @model.
97 	 *
98 	 * Params:
99 	 *     model = the model to sort
100 	 *     sorter = the `GtkSorter` to sort @model with,
101 	 *
102 	 * Returns: a new `GtkSortListModel`
103 	 *
104 	 * Throws: ConstructionException GTK+ fails to create the object.
105 	 */
106 	public this(ListModelIF model, Sorter sorter)
107 	{
108 		auto __p = gtk_sort_list_model_new((model is null) ? null : model.getListModelStruct(), (sorter is null) ? null : sorter.getSorterStruct());
109 
110 		if(__p is null)
111 		{
112 			throw new ConstructionException("null returned by new");
113 		}
114 
115 		this(cast(GtkSortListModel*) __p, true);
116 	}
117 
118 	/**
119 	 * Returns whether incremental sorting is enabled.
120 	 *
121 	 * See [method@Gtk.SortListModel.set_incremental].
122 	 *
123 	 * Returns: %TRUE if incremental sorting is enabled
124 	 */
125 	public bool getIncremental()
126 	{
127 		return gtk_sort_list_model_get_incremental(gtkSortListModel) != 0;
128 	}
129 
130 	/**
131 	 * Gets the model currently sorted or %NULL if none.
132 	 *
133 	 * Returns: The model that gets sorted
134 	 */
135 	public ListModelIF getModel()
136 	{
137 		auto __p = gtk_sort_list_model_get_model(gtkSortListModel);
138 
139 		if(__p is null)
140 		{
141 			return null;
142 		}
143 
144 		return ObjectG.getDObject!(ListModelIF)(cast(GListModel*) __p);
145 	}
146 
147 	/**
148 	 * Estimates progress of an ongoing sorting operation.
149 	 *
150 	 * The estimate is the number of items that would still need to be
151 	 * sorted to finish the sorting operation if this was a linear
152 	 * algorithm. So this number is not related to how many items are
153 	 * already correctly sorted.
154 	 *
155 	 * If you want to estimate the progress, you can use code like this:
156 	 * ```c
157 	 * pending = gtk_sort_list_model_get_pending (self);
158 	 * model = gtk_sort_list_model_get_model (self);
159 	 * progress = 1.0 - pending / (double) MAX (1, g_list_model_get_n_items (model));
160 	 * ```
161 	 *
162 	 * If no sort operation is ongoing - in particular when
163 	 * [property@Gtk.SortListModel:incremental] is %FALSE - this
164 	 * function returns 0.
165 	 *
166 	 * Returns: a progress estimate of remaining items to sort
167 	 */
168 	public uint getPending()
169 	{
170 		return gtk_sort_list_model_get_pending(gtkSortListModel);
171 	}
172 
173 	/**
174 	 * Gets the sorter that is used to sort @self.
175 	 *
176 	 * Returns: the sorter of #self
177 	 */
178 	public Sorter getSorter()
179 	{
180 		auto __p = gtk_sort_list_model_get_sorter(gtkSortListModel);
181 
182 		if(__p is null)
183 		{
184 			return null;
185 		}
186 
187 		return ObjectG.getDObject!(Sorter)(cast(GtkSorter*) __p);
188 	}
189 
190 	/**
191 	 * Sets the sort model to do an incremental sort.
192 	 *
193 	 * When incremental sorting is enabled, the `GtkSortListModel` will not do
194 	 * a complete sort immediately, but will instead queue an idle handler that
195 	 * incrementally sorts the items towards their correct position. This of
196 	 * course means that items do not instantly appear in the right place. It
197 	 * also means that the total sorting time is a lot slower.
198 	 *
199 	 * When your filter blocks the UI while sorting, you might consider
200 	 * turning this on. Depending on your model and sorters, this may become
201 	 * interesting around 10,000 to 100,000 items.
202 	 *
203 	 * By default, incremental sorting is disabled.
204 	 *
205 	 * See [method@Gtk.SortListModel.get_pending] for progress information
206 	 * about an ongoing incremental sorting operation.
207 	 *
208 	 * Params:
209 	 *     incremental = %TRUE to sort incrementally
210 	 */
211 	public void setIncremental(bool incremental)
212 	{
213 		gtk_sort_list_model_set_incremental(gtkSortListModel, incremental);
214 	}
215 
216 	/**
217 	 * Sets the model to be sorted.
218 	 *
219 	 * The @model's item type must conform to the item type of @self.
220 	 *
221 	 * Params:
222 	 *     model = The model to be sorted
223 	 */
224 	public void setModel(ListModelIF model)
225 	{
226 		gtk_sort_list_model_set_model(gtkSortListModel, (model is null) ? null : model.getListModelStruct());
227 	}
228 
229 	/**
230 	 * Sets a new sorter on @self.
231 	 *
232 	 * Params:
233 	 *     sorter = the `GtkSorter` to sort @model with
234 	 */
235 	public void setSorter(Sorter sorter)
236 	{
237 		gtk_sort_list_model_set_sorter(gtkSortListModel, (sorter is null) ? null : sorter.getSorterStruct());
238 	}
239 }